/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package webservice;

import java.io.File;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;

import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
import servlet.Servlet;

/**
 * REST Web Service
 *
 * @author Nguyen Trung
 */
@Path("query")
public class QueryResource {


    @Context 
    private ServletContext servletContext ; 
    @Resource
    private WebServiceContext wsc;
    

//    @Context 
//    ServletContext context; //you can specify in your method argument
//    String realPath = context.getRealPath("/");
    /** Creates a new instance of QueryResource */
    public QueryResource() {
    }

    /**
     * Retrieves representation of an instance of webservice.QueryResource
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("text/plain")
    public String getText() throws IOException {

        try
        {
            //MessageContext messageContext = wsc.getMessageContext();

            //ServletContext ctx = (ServletContext) 
            //messageContext.getProperty(MessageContext.SERVLET_CONTEXT);
        //Question.readQuestion();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return "trung";
    }

    /**
     * PUT method for updating or creating an instance of QueryResource
     * @param content representation for the resource
     * @return an HTTP response with content of the updated or created resource.
     */
    @PUT
    @Consumes("text/plain")
    public void putText(String content) {
    }

    public void myServiceOperation() {

        MessageContext ctxt = wsc.getMessageContext();
        ServletContext req = (ServletContext) ctxt.get(MessageContext.SERVLET_CONTEXT);
        System.out.println(req.getContextPath());
        //return req.getRealPath("/");
    }
}
